package com.tony.firewall;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.tony.firewall.adapter.SessionListAdapter;
import com.tony.firewall.R;

public class MessageListFragment extends Fragment {
	private ListView mListView;
	private SessionListAdapter mAdapter;

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		mListView.setAdapter(mAdapter);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.layout_listview, container, false);

		mListView = (ListView) view.findViewById(R.id.lv_listview);
		mListView.setAdapter(mAdapter);
		mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
		mListView.setOnItemClickListener(mOnItemClickListener);
//		mListView.setMultiChoiceModeListener(new MessageMultiChoiceListener());

		return mListView;
	}

	public void setAdapter(SessionListAdapter adapter) {
		mAdapter = adapter;
	}

	private OnItemClickListener mOnItemClickListener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			if (parent == mListView) {
				// if (parent.getId() == R.id.lv_session_list) {
				Intent intent = new Intent(getActivity(), MessageListActivity.class);
				intent.putExtra("address", mAdapter.getItem(position).getAddress());
				startActivity(intent);
			}
		}
	};

}
